<template>
  <div class="edit_container">
    <div class="btn_box">
      <el-button @click.stop="goBack">返回</el-button>
    </div>
    <Rehab ref="rehab" form-type="view" :patient-info="patientInfo" :assess-info="assessInfo" :doctor-type="doctorType" title="中期康复评定记录" :signType="signType"/>
    <div class="hand_sign_files" v-if="signType == 2">
      <div>患者签字：</div>
      <div class="file_list">
        <a v-for="(file, index) in signFileList" :key="index" class="file_item" :href="file.url" download>{{ file.name }}</a>
      </div>
    </div>
  </div>
</template>

<script>
import Rehab from '../../assessSys/components/rehab.vue'
import { recoveryDetail } from '@/api/treatment/treatment.js'
import moment from 'moment'

export default {
  name: 'EarlyView',
  components: { Rehab },
  data() {
    return {
      assessId: 0,
      type: 0,
      source: 1,
      patientInfo: {},
      assessInfo: {},
      signType: 1,
      signFileList: []
    }
  },
  computed: {
    doctorType() {
      const sourceMap = {
        1: 'hospital',
        2: 'outpatient',
        3: 'therapists'
      }
      return sourceMap[this.source]
    }
  },
  mounted() {
    this.type = this.$route.query.type || 0
    this.source = this.$route.query.source
    this.assessId = this.$route.query.id
    this.getAssessInfo()
  },
  methods: {
    getAssessInfo(assessId) {
      // 执行获取治疗详情
      recoveryDetail({
        type: this.type,
        evaluateSource: this.source,
        relationId: this.assessId,
        estimateType: 2
      }).then(res => {
        this.patientInfo = {
          ...res.content,
          genderName: res.content.gender === 0 ? '女' : '男'
        }
        if (res.content.evaluateTime) {
          res.content.evaluateTime = moment(res.content.evaluateTime).format('YYYY-MM-DD HH:mm')
        }
        this.assessInfo = {
          ...this.assessInfo,
          ...res.content
        }
        this.signType = res.content.patientSignType
        this.signFileList = res.content.patientSign ? JSON.parse(res.content.patientSign) : []
      })
    },
    goBack() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped>
@import url('./style.scss');
.hand_sign_files{
  width: 750px;
  margin: 0 auto;
  display: flex;
  .file_list{
    .file_item{
      color: #1890ff;
    }
  }
}
</style>
